package com.dwjm.shop.goods;

import com.dwjm.shop.merchant.MerchantDao;
import com.dwjm.shop.merchant.MerchantDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;




@WebServlet("/addGoods")
public class GoodsHandler extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String name = req.getParameter("title");
        String price = req.getParameter("price");
        String desc = req.getParameter("desc");
        String img = req.getParameter("img");
        String mid = req.getParameter("mid");

Goods goods =new Goods(null,title,new BigDecimal(price),desc,img,"0",Integer.parseInt(mid));
GoodDao merchantDao = new GoodDaoImpl();
int i = merchantDao.addGoods(goods);
if(1 == i){
    resp.getWriter().write("Y");
}else {
    resp.getWriter().write("N");
}
    }
}
